﻿using Anata_Client;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication2.Model;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        //public static ArrayList transaksi = new ArrayList();
        public ArrayList transaksiLayanan = new ArrayList();
        public ArrayList transaksiProduk = new ArrayList();
        public static int currentId;
        public static int idCabang = 1;
        int idTransaksi;

        public Form1()
        {
            InitializeComponent();

            currentId = 1;
            object[] o = new object[2];
            string s;

            dgvTransaksi.Columns.Add("IdTransaksi", "IdTransaksi");
            dgvTransaksi.Columns.Add("Id", "Id");
            dgvTransaksi.Columns.Add("Nama", "Nama");
            for (int i = 0; i < currentId; ++i)
            {
                s = find(i);
                if (s != "")
                {
                    o[0] = i;
                    o[1] = s;
                    dgvTransaksi.Rows.Add(o);
                }
            }
        }

        public Form1(ref ArrayList a, ref ArrayList b)
        {
            InitializeComponent();

            transaksiLayanan = a;
            transaksiProduk = b;
            object[] o = new object[3];
            string s;

            dgvTransaksi.Columns.Add("IdTransaksi", "IdTransaksi");
            dgvTransaksi.Columns.Add("Id", "Id");
            dgvTransaksi.Columns.Add("Nama", "Nama");
            for (int i = 0; i < currentId; ++i)
            {
                s = find(i);
                if (s != "")
                {
                    o[0] = idTransaksi;
                    o[1] = i;
                    o[2] = s;
                    dgvTransaksi.Rows.Add(o);
                }
            }
        }

        public string find(int n)
        {
            object[] temp;

            for (int i = 0; i < transaksiLayanan.Count; ++i)
            {
                temp = (object[])transaksiLayanan[i];
                if ((int)temp[2] == n)
                {
                    idTransaksi = (int)temp[0];
                    return (string)temp[3]; 
                }
            }

            return "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(ref transaksiLayanan, ref transaksiProduk, currentId, dgvTransaksi);
            form2.Show(this);
            //this.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form5 form5 = new Form5(ref transaksiLayanan, ref transaksiProduk);
            form5.Show(this);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2(ref transaksiLayanan, ref transaksiProduk, currentId, dgvTransaksi);
            f.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            //Edit
            DataGridViewRow dr = dgvTransaksi.CurrentRow;

            Form2 f = new Form2(ref transaksiLayanan, ref transaksiProduk, (int)dr.Cells[0].Value, (int)dr.Cells[1].Value, (string)dr.Cells[2].Value, dgvTransaksi);
            f.Show();
        }

        private void mnuKonfigurasi_Click(object sender, EventArgs e)
        {
            //Menampilkan konfigurasi cabang
            frmAuthentication f = new frmAuthentication();
            f.Show();
        }

        private void btnSelesai_Click(object sender, EventArgs e)
        {
            frmPembayaran f = new frmPembayaran();
            f.Show();
        }

        private void btnBayar_Click(object sender, EventArgs e)
        {
            DataGridViewRow dr = dgvTransaksi.CurrentRow;

            frmPembayaran f = new frmPembayaran((int)dr.Cells[0].Value, transaksiLayanan, transaksiProduk);
            f.Show();
        }
    }
}
